#! /bin/sh

# Kenton's Code Playground -- http://code.google.com/p/kentons-code
# Author: Kenton Varda (temporal@gmail.com)
# Copyright (c) 2010 Google, Inc. and contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

if test $# = 0; then
  # Ekam is querying the script.  Tell it that we care about modc files.
  echo trigger filetype:.modc
  exit 0
fi

echo findInput "$1"
read INPUT

echo findProvider file:modc/modc-fmt
read MODC_FMT

if test "$MODC_FMT" = ""; then
  echo "error:  couldn't find modc-fmt." >&2
  exit 1
fi

echo newOutput "${1}.formatted"
read OUTPUT
echo newOutput "${1}.html"
read HTML_OUTPUT

$MODC_FMT < $INPUT > $OUTPUT
$MODC_FMT --html < $INPUT > $HTML_OUTPUT

diff -u $INPUT $OUTPUT >&2 && echo passed
